package pkg;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import Utility.MessageUtility;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import xmlMapping.Message;

/**
 *
 * @author labib
 */
public class DispMsg extends SimpleTagSupport {
    private int msgId;
 
    /**
     * Called by the container to invoke this tag. 
     * The implementation of this method is provided by the tag library developer,
     * and handles all tag processing, body iteration, etc.
     */
    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        Integer id=(Integer)getJspContext().getAttribute("id");
        System.out.println(" id in simple tag is "+id);
        try {
        MessageUtility utility=new MessageUtility();
           Message msg= utility.getMessage(msgId);
           
           out.print("<h1>sender is </h1><h2>"+msg.getMemberBySenderId().getUserName()+"</h2><br>   <br> ");
           out.print("<h1>Message  Title </h1><h2>"+msg.getTitle()+"</h2><br>   <br> ");
           out.print("<h1>message Body</h1><h2>");
           out.print(msg.getBody()+"</h2><br>   <br> ");
           out.print("<h1>date of send is </h1>\t\t    <h2>"+msg.getDate()+"</h2>");
           
            JspFragment f = getJspBody();
            if (f != null) f.invoke(out);

            // TODO: insert code to write html after writing the body content.
            // e.g.:
            //
            // out.println("    </blockquote>");

        } catch (java.io.IOException ex) {
            throw new JspException("Error in DispMsg tag", ex);
        }
    }

    public void setMsgId(int msgId) {
        this.msgId = msgId;
    }

}
